package ypmits.utils {

	public class ArrayTools {
		public static function clone( _arr : Array ) : Array {
			
			var a : Array = [];
			
			for (var i : * in _arr ) {
				a[i] = _arr[i];
			}
			
			return a;
		}

		
		/**
		 * This function shifts an array to a certain ammount
		 * @param popnums The number of places it has to shift to the right
		 * @param whicharray The target-array
		 */
		public static function shifter( popnums : int, whicharray : Array ) : Array {
			var a : Array = clone( whicharray );
			for( var i : int = 0; i < popnums; i++ ) {
				a.unshift( a.pop( ) );
			}
			return a;
		}
		
		
		/**
		 * This function removes duplicates from an Array
		 * @param array Array The array from which to remove the duplicates
		 * @return Array A fresh new cleaned-up array
		 */
		public static function removeDuplicates( array : Array ) : Array {
			var z : Array = array.filter(
			function ( a : * ) : Boolean { 
				return ((z ? z : z = new Array( )).indexOf( a ) >= 0 ? false : (z.push( a ) >= 0)); 
			}, null );

			return z;
		}
	}
}
